﻿using System;

namespace EnterpriseLibraryExtensions.Services.Mapping
{
    internal class ArrayCollectionHandler : ICollectionHandler
    {
        private readonly Array _array;
        private int _index;

        public ArrayCollectionHandler(Type elementType, int length)
        {
            _array = Array.CreateInstance(elementType, length);
            _index = 0;
        }

        public void AddElement(object element)
        {
            _array.SetValue(element, _index++);
        }

        public object CreateInstance()
        {
            return _array.Clone();
        }
    }
}
